package com.wbao.dianniu.utils;

import java.util.ArrayList;

import android.content.Context;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.wbao.dianniu.logical.GlobalContext;
import com.wbao.dianniu.R;

/**
 * 网络图片处理工具类
 * 
 * @author yejianjun
 *
 */
public class PictureDownloadUtils {
	//namespace
	public static final String namespace = "dianniu";
	private static  PictureDownloadUtils instance;
	String mTaskId;
	
	public static PictureDownloadUtils getInstance(){
		if(null == instance){
			instance = new PictureDownloadUtils();
		}
		return instance;
	}
	
	/**
	 * String 图片数组转成list
	 * 
	 * @param str
	 * @return
	 */
	public ArrayList<String> stringToList(String str){
		ArrayList<String> list = new ArrayList<String>();
		String[] result = str.split(",");
		for (int i = 0; i < result.length; i++) {
			list.add(GlobalContext.cdndownUrl + result[i]);
		}
		return list;	
	}
	
	/**
	 * 自身头像--大图查看 支持缩放
	 * 
	 * @return
	 */
	/*public static DisplayImageOptions  getHeadOptions(){
		DisplayImageOptions options = new DisplayImageOptions.Builder()  
        .showImageOnLoading(R.drawable.default_head_icon) // resource or drawable  
        .showImageForEmptyUri(R.drawable.default_head_icon) // resource or drawable  
        .showImageOnFail(R.drawable.default_head_icon) // resource or drawable  
        .delayBeforeLoading(1000)  
        .cacheInMemory(true) // default  
        .cacheOnDisk(false) // default  
        .imageScaleType(ImageScaleType.NONE) // default  
        .bitmapConfig(Bitmap.Config.RGB_565) // default  
        .delayBeforeLoading(100)//载入图片前稍做延时可以提高整体滑动的流畅度
        .build();
		return options;
	}*/
	
	/**
	 * 加载头像并显示  图片地址没带前缀
	 * 
	 * @param headIV
	 * @param headUrl
	 */
	public static void displayHeadImage(Context context, ImageView view,String headPic) {
		String downUrl = GlobalContext.cdndownUrl + headPic ; //+ "@100-1ci.png";
		Glide.with(context)
		.load(downUrl)
		.centerCrop()
		.placeholder(R.drawable.default_head_icon)
		.crossFade()
		.override(Utils.dip2px(context, 40), Utils.dip2px(context, 40))
		.bitmapTransform(new GlideCircleTransform(context))
		.thumbnail(0.2f)
		.into(view);
	}
	
	
	/**
	 * 加载头像并显示 图片地址带了前缀
	 * 
	 * @param headIV
	 * @param headUrl
	 */
	public static void displayHeadNotPrefix(Context context, ImageView view,String headPic) {
		Glide.with(context)
		.load(headPic)
		.centerCrop()
		.placeholder(R.drawable.default_head_icon)
		.crossFade()
		.override(Utils.dip2px(context, 40), Utils.dip2px(context, 40))
		.thumbnail(0.2f)
		.into(view);
	}
	
}
